nums=[1,2,3,5,1,2]
#暴力求解
def findPeakElement(nums):
    nums_len=len(nums)
    pointer=0
    while pointer<nums_len:
        if pointer==0:
            if nums[pointer]>nums[pointer+1]:
                return pointer
        elif pointer==nums_len-1:
            #最后一个索引位置时
            if nums[pointer]>nums[pointer-1]:
                return pointer
        else:
            if nums[pointer]>nums[pointer+1] and nums[pointer]>nums[pointer-1]:
                return pointer
        pointer+=1
#二分查找求解
def findPeakElement_1(nums):
    nums_len=len(nums)
    if nums_len==1:
        #如果序列中只存在一个元素，那么它就是峰值
        return 0
    l,r=0,nums_len-1
    while l<r:
        mid=l+r>>1
        if nums[mid]>nums[mid+1]:
            r=mid
        else:
            l=mid+1
    return r
print(findPeakElement_1(nums))

